/*
Function to set checked value to the checkbox of the row
*/
function setcheckedvalue(row,itm_id)
{/*
	if(document.getElementById(itm_id).checked==true)
		row.style.background='#FFC';
	else row.style.background='';
	
	document.getElementById(itm_id).click();*/
}
 
/* Function to change the background color of the tr when mouse-over */
function setBgColor_MouseOverRow(row,itm_id)
{
	if(document.getElementById(itm_id).checked==false)
		row.style.background='#F7F7F7';
}

function setBgColor_MouseOutRow(row,itm_id)
{
	if(document.getElementById(itm_id).checked==false)
		row.style.background='';
}

function changeBgColorAllTR(mycheckbox)
{
	//Please check the error
	
	
	/*
	if(document.getElementsByTagName)
	{
		if(mycheckbox.checked==true)
			var mycolor="#FFC";
		else
			var mycolor='';
		var table = document.getElementById("mytable");  
		var rows = table.getElementsByTagName("tr");
		for(var i = 3; i < rows.length-3; i++)
			rows[i].style.background = mycolor;
	}
	*/
}
//***********************************************************
//***********************************************************

function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}
/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message, alrt) {

	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	
	if (formElement.value == '') {
		_isEmpty = true;
		if(alrt){
			alert(message);
			formElement.focus();
		}
	}
	return _isEmpty;
}
/*
Function check the username formart allow only letters, numbers, and underscores
*/
function isWrongFormart(formElement, message, alrt) {
	string = trim(formElement.value);
	
	_isWrongFormart = false;
	var illegalChars = /\W/;
  // allow only letters, numbers, and underscores
    if (illegalChars.test(string)) {
//       error = "The username contains illegal characters.\n";
		_isWrongFormart = true;
		if(alrt){
			alert(message);
			formElement.focus();
		}
	}
	
	return _isWrongFormart;
}
/*
Function check the username length
*/
function isWrongLength(formElement, message, alrt) {
	string = trim(formElement.value);
	
	_isWrongLength = false;
	if ((string.length < 5) || (string.length > 20)) {
		_isWrongLength = true;
		if(alrt){
			alert(message);
			formElement.focus();
		}
	}
	
	return _isWrongLength;
}

/*
Function check the password formart allow only letters and numbers
*/
function isWrongFormartLetNum(formElement, message, alrt) {
	string = trim(formElement.value);
	
	_isWrongFormart = false;
	var illegalChars = /[\W_]/;
  // allow only letters and numbers
    if (illegalChars.test(string)) {
//       error = "The password contains illegal characters.\n";
		_isWrongFormart = true;
		if(alrt){
			alert(message);
			formElement.focus();
		}
	}
	
	return _isWrongFormart;
}
/*
	Check if two form elements are equal.
	If it is display an alert box and focus
	on the element
*/
function isNotEqual(formElement1,formElement2, message) {
	formElement1.value = trim(formElement1.value);
	formElement2.value = trim(formElement2.value);
	
	_isEqual = false;
	if (formElement1.value != formElement2.value) {
		_isEqual = true;
		alert(message);
		formElement2.focus();
	}
	
	return _isEqual;
}
/*
Function detect valid email
*/
function isNotEmail(formElement, message)
{
	formElement.value = trim(formElement.value);
	
	_isEmail = false;
	if(formElement.value.indexOf ('@',0) == -1 || formElement.value.indexOf ('.',0) == -1) {
		alert(message);
		formElement.select();
		formElement.focus();
		_isEmail = true;
	}
	return _isEmail;
}